feat(config): add setting to make directory tree context configurable#19053
feat(config): add setting to make directory tree context configurable#19053kevin-ramdass wants to merge 3 commits intomainfrom
Conversation
…de the directory structure in the environment context.
Summary of ChangesHello @kevin-ramdass, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new configuration option that allows users to control the inclusion of the workspace directory tree in the initial context provided to the model. This enhancement addresses concerns related to context window limitations for large workspaces by providing an opt-out mechanism for sending the full directory structure, thereby improving flexibility and resource management for users. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Hi @kevin-ramdass, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Size Change: +685 B (0%) Total Size: 24.4 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable new setting, context.includeDirectoryTree, allowing users to exclude the directory tree from the initial context. While the implementation is solid, a critical prompt injection vulnerability was identified: workspace information (file and directory names) is embedded into the LLM prompt without sanitization, which could be exploited by a malicious workspace to manipulate the model's behavior. Additionally, a minor formatting issue in the prompt construction adds an extra newline.
| My operating system is: ${platform} | ||
| The project's temporary directory is: ${tempDir} | ||
| ${directoryContext} | ||
| ${directoryContext ? directoryContext + '\n' : ''} |
There was a problem hiding this comment.
The directoryContext variable is directly embedded into the LLM prompt within a <session_context> block without sanitization, making it vulnerable to prompt injection. An attacker could create a file or directory with a name containing the </session_context> closing tag followed by malicious instructions, potentially leading to unauthorized tool execution. Remediation: Sanitize directoryContext by escaping or removing any occurrences of the </session_context> tag before embedding it. Additionally, this line introduces an extra newline in the session context, which could subtly affect model behavior.
| ${directoryContext ? directoryContext + '\n' : ''} | |
| ${directoryContext ? directoryContext.replace(/<\/session_context>/g, '') + '\n' : ''} |
…de the directory structure in the environment context.
…de the directory structure in the environment context.
Summary
Adds a new advanced setting
context.includeDirectoryTreeto control whether the workspace directory tree is included in the initial session context sent to the model. This allows users with very large workspaces or specific context window concerns to opt out of sending the full directory structure by default.Details
includeDirectoryTreeboolean setting (default:true) to settingsSchema.ts under thecontextcategory.showInDialog: falseso it acts as an advanced configuration and does not clutter the settings UI.clipackage down to the Config class in thecorepackage.false.settings.mddocumentation.Related Issues
Related to #15328
How to Validate
npm run test~/.gemini/settings.json:npm run startin the workspace.